package router

import (
	_ "OJCenter/docs"
	"OJCenter/middleware"
	"OJCenter/router/api"
	"github.com/gin-gonic/gin"
	swaggerFiles "github.com/swaggo/files"
	swagger "github.com/swaggo/gin-swagger"
)

func RouterInit(a *api.Api) *gin.Engine {
	// 路由组中添加中间件
	r := gin.Default()
	r.Use(gin.Recovery())
	r.Use(middleware.Cors())
	//r.Use(middleware.Tls())

	r.POST("/auth", a.GetAuth)

	authorized := r.Group("/api/v1")
	authorized.Use(middleware.JWT(a.M))
	{
		InitAuthorityRouter(a, authorized)
		InitNoticeRouter(a, authorized)
		InitContestRouter(a, authorized)
		InitSubmissionRouter(a, authorized)
		InitProblemRouter(a, authorized)
	}

	r.GET("/swagger/*any", swagger.WrapHandler(swaggerFiles.Handler))

	return r
}
